#user custom

source "$1"

App_Process="$app_name_prefix"
App_Name="$app_name"

Update_Firmware_Process="UpdateFirmware"
Update_Firmware="$Update_Firmware_Process.app"

Auto_Update_Manager_Process="AutoUpdateManager"
Auto_Update_Manager="$Auto_Update_Manager_Process.app"

Autorunfile_path="/Library/LaunchAgents/cn.com.zte.usbswapper.plist"
Filter_path="/Library/LaunchAgents/cn.com.zte.usbfilter.plist"

Uninstall_File="Uninstall $App_Name"

MiniUI="MiniUI"
UnsTxt="UninstallZTEDatacardDriver.txt"

#app_root="/Applications"
#drv_root="/System/Library/Extensions"
#drv_names="ZTEUSBCDCACMData.kext ZTEUSBCDCACMControl.kext"
#recp_root="/Library/Receipts"
#inst_comps="app.pkg drv.pkg"

ModemList="$pref_root"
ModemScript="/Library/Modem Scripts/ZTE USB MODEM"

#
# ZTEPPPMonitor
#
PPPMonitor_config="/Library/LaunchDaemons/cn.com.zte.PPPMonitor.plist"
PPPMonitor_file="/Library/Application Support/ZTE/PPPMonitord"

#
# MessageCenter
#
MessageCenter_config="/Library/LaunchDaemons/cn.com.zte.MessageCenter.plist"
MessageCenter_file="/Library/Application Support/ZTE/MessageCenter"

#
# Update
#
Update_path="/System/Library/Auto_Update"


echo "######################### Begin unload ############################"
echo ""
echo ""

#
# Unload usbswapper : this operation do not use as root!!
#
# launchctl unload "$Autorunfile_path"
# killall Mac_SwapperDemon



echo "###################################################################"
echo "#                                                                 #"
echo "#                 Begin high privilege operation!                 #"
echo "#                                                                 #"
echo "###################################################################"
echo ""
echo ""

# Unload PPPMonitor
if [ "x$PPPMonitor_config" != "x" ]; then
	launchctl unload "$PPPMonitor_config"
	rm -f "$PPPMonitor_config"
fi

# Unload MessageCenter
if [ "x$MessageCenter_config" != "x" ]; then
	launchctl unload "$MessageCenter_config"
	rm -f "$MessageCenter_config"
fi


rm -Rf "/Library/Application Support/ZTE"


echo "########################## delete usbswapper ######################"
if [ "x$Autorunfile_path" != "x" ]; then
	rm -f "$Autorunfile_path"
fi

echo "########################## delete Filter driver ###################"
if [ "x$Filter_path" != "x" ]; then
	launchctl unload "$Filter_path"
	rm -f "$Filter_path"
fi
killall "ZTEUSBFilter"

echo "########################## unload drivers #########################"
echo ""
echo ""
cd "$drv_root"
for drv_item in $drv_names; do
	echo "Delete driver $drv_item"
	kextunload "$drv_item"
	rm -R "$drv_item"
done
touch -fm "$drv_root"


echo "####################### delete configuration ######################"
if [ "x$ModemList" != "x" ]; then
	rm -Rf "$ModemList"
fi

echo "######################## delete modemscript #######################"
if [ "x$ModemScript" != "x" ]; then
	rm -f "$ModemScript"
fi

echo "############################ delete UI ############################"
echo ""
echo ""
cd "$app_root"

killall "$App_Process"
MacUI="$app_root/$App_Name"
if [ "x$MacUI" != "x" ]; then
	rm -Rf "$MacUI"
fi


echo "####################### delete update files #######################"
killall "$Update_Firmware_Process"
firmware="$app_root/$Update_Firmware"
if [ "x$firmware" != "x" ]; then
	rm -Rf "$firmware"
fi

killall "$Auto_Update_Manager_Process"
updatemanger="$app_root/$Auto_Update_Manager"
if [ "x$updatemanger" != "x" ]; then
	rm -Rf "$updatemanger"
fi

if [ "x$Update_path" != "x" ]; then
	rm -Rf "$Update_path"
fi

echo "######################### delete others ###########################"
if [ "x$MiniUI" != "x" ]; then
	rm -f "$MiniUI"
fi

if [ "x$UnsTxt" != "x" ]; then
	rm -f "$UnsTxt"
fi

echo "######################### delete uninstall file ################################"
uninstall="$app_root/$Uninstall_File"
if [ "x$uninstall" != "x" ]; then
	rm -Rf "$uninstall"
fi

echo "################## Uninstall finished successfully! ###############"


